<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<table cellspacing="0" border="0" width="995">
	<tr>
		<td width="995" class="title_manager_product">Quản lý sản phẩm</td>
	</tr>
	<tr>
		<td height="90">
			<table border="0" cellpadding="0" cellspacing="0" width="995">
				<tr>
					<td align="center">
						<table border="0" cellpadding="0" cellspacing="0">
							<tr>
								<td align="center"><a href="index.php?admin=productAdmin&do=formaddcategory"><img src="images/CreateNews.gif" width="48" height="47" border="0" /></a></td>
							</tr>
							<tr>
								<td align="center" class="title_new_add"><a href="index.php?admin=productAdmin&do=formaddcategory">Tạo danh mục sản phẩm</a></td>
							</tr>
						</table>
						
					</td>
					
					<td align="center">
						<table border="0" cellpadding="0" cellspacing="0">
							<tr>
								<td align="center"><a href="index.php?admin=productAdmin&do=formaddgroup"><img src="images/CreateCategory.gif" width="51" height="48" border="0" /></a></td>
							</tr>
							<tr>
								<td align="center" class="title_new_add"><a href="index.php?admin=productAdmin&do=formaddgroup">Tạo nhóm sản phẩm</a></td>
							</tr>
						</table>
						
					</td>
					
					<td align="center">
						<table border="0" cellpadding="0" cellspacing="0">
							<tr>
								<td align="center"><a href="index.php?admin=productAdmin&do=formaddproduct"><img src="images/CreateCategory.gif" width="51" height="48" border="0" /></a></td>
							</tr>
							<tr>
								<td align="center" class="title_new_add"><a href="index.php?admin=productAdmin&do=formaddproduct">Thêm mới sản phẩm</a></td>
							</tr>
						</table>
						
					</td>
					
				</tr>
			</table>
		</td>	
	</tr>
</table>
<table cellspacing="4" cellpadding="0" border="0" width="995">
	<tr>
		<td width="200" valign="top">					
			<?php
				include("menuleftcategory.php");
			?>
		</td>	
		<td width="795" valign="top">
			<?php
				$id=$_GET['id'];
				//print_r($id);
			?>
			<form action="index.php?admin=productAdmin&do=formeditgroup&id=<?php echo $id;?>" method="post" enctype="multipart/form-data">
			<table cellspacing="0" border="0" width="790">
				<tr>
					
					<td width="790" class="title_manager_cate">Sửa nhóm sản phẩm</td>
				
				</tr>
			</table>
			<table class="reference" cellspacing="6" cellpadding="0" border="1" width="100%">
			<tr>
				<td colspan="2" align="center">
					<?php
						$id=$_GET['id'];
						
						$groupName = $_POST['groupName'];
						
						$target="../user/upload/groupCate/";
						$image = $_FILES['groupImage']['name'];
						$link=$target.$image;
						
						if(isset($_POST['submit'])){
							move_uploaded_file($_FILES['groupImage']['tmp_name'],$link);
							
							if($image==''){
								$query="UPDATE groupcategories SET groupName='$groupName' WHERE id=$id";
							}else{
								$query="UPDATE groupcategories SET groupName='$groupName',groupImage='$link' WHERE id=$id";
							}
							if($groupName==''){
								echo "<font color=\"red\">Bạn phải nhập vào tên nhóm sản phẩm.</font>";
							}else{															
								mysql_query($query);
								echo "Nhóm sản phẩm đã được sửa thành công.";
								echo "<script>window.location='index.php?admin=productAdmin&do=listproduct'</script>";	
							}	
						}
							
					?>
				</td>
			</tr>
			<?php
				$query="SELECT * FROM groupcategories WHERE id=$id";
				$result=mysql_query($query);
				while($row=mysql_fetch_array($result)){?>
					<tr>
						<td width="200" align="right"><b>Tên nhóm sản phẩm:</b></td>
						<td>
							<input type="text" name="groupName" size="40" value="<?php echo $row['groupName']?>" />
						</td>
					</tr>
				   <!--
					<tr>
						<td>Danh mục sản phẩm:</td>
						<td>
							<select name="cateID">
								<option value="">Danh mục sản phẩm</option>
								<?php					
								$query2 = "select * from categories";
								$result2 = mysql_query($query2);
								while($row2 = mysql_fetch_array($result2)){
									if($row2['id']==$row['cateID']){
								?>
									<option value="<?php echo $row2['id']?>" selected="selected"><?php echo $row2['cateName'];?></option>	
								<?php
								}
							  }
								?>
							 </select>
						</td>
					</tr>
					-->
					<tr>
						<td align="right"><b>Ảnh sản phẩm:</b></td>
						<td>
							<input type="file" name="groupImage" />
						</td>
					</tr>
			<?php
			}
			?>   	      	 
				   <tr>
						<td></td>
						<td>
							<input type="submit" name="submit" value="Sửa nhóm sản phẩm" />
							<input type="button" name="Cancel" value="Cancel" onclick="window.location = 'index.php?admin=productAdmin&do=listproduct' " /> 
						<td>
				   </tr>
				</table>
			</form>
		</td>
	</tr>	
</table>
</body>
</html>